/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: jse2302 - T8
 * <p>Powered by webrx On 2023-06-30 17:05:01
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T8 implements Runnable{

    @Override
    public void run() {
        String t = Thread.currentThread().getName();
        System.out.println(t + "线程启动....");
        while (running) {

        }
        System.out.println(t + "线程结束");
    }

    //volatile synchronized区别？
    volatile boolean running = true;

    int work() {
        String t = Thread.currentThread().getName();
        System.out.println(t + "线程启动....");
        while (running) {

        }
        System.out.println(t + "线程结束");
        return 0;

    }

    public static void main(String[] args) {
        var t = new T8();
        new Thread(t::work, "work1").start();
        new Thread(t::work, "work2").start();
        new Thread(t, "work3").start();

        try{
            Thread.sleep(6);
        }catch(Exception e){
            e.printStackTrace();
        }

        t.running = false;
        System.out.println("ok");
    }
}
